<?php
include("../includes/common.php");
$title='批量对接商品';
include './head.php';

if($islogin==1){}else exit("<script language='javascript'>window.location.href='./login.php';</script>");
adminpermission('shop', 1);
$act=$_GET['act'];
if($act==''){
    $rs=$DB->query("SELECT * FROM pre_shequ where type='sf' order by id asc");
    $shequselect='';
    while ($res=$rs->fetch()) {
        if($res['type']=='sf'){
            $res['type']='FGSUP商城系统';
        }
		$shequselect .='<option value="'.$res['id'].'" type="'.$res['type'].'" domain="'.$res['url'].'">[<font color=blue>'.$res['type'].'</font>] '.$res['url'].($res['remark']?' ('.$res['remark'].')':'').'</option>';
    }
    if(empty($shequselect)){
        $shequselect='<option value="">--暂未添加异世界云商系统--</option>';
    }
    echo '<div class="col-sm-8 col-md-6 center-block" style="float: none;">
            <div class="block">
                <div class="block-title">
                    <h3 class="panel-title">批量对接商品</h3>
                    <a href="./sf_synchronization.php" class="pull-right btn btn-default btn-sm" style="margin-top:5px;margin-right:5px">
                        <i class="fa fa-cog"></i> 自动同步设置
                    </a>
                </div><div class="">
    		<div class="alert alert-info">
                批量对接商品目前只支持异世界云商系统对接的类型。使用此功能可以快速添加/更新本站对接的商品。
            </div>
            <form action="?" method="GET" role="form">
    		    <input type="hidden" name="act" value="data">
    			<div class="form-group">
    				<div class="input-group">
    				    <div class="input-group-addon">对接站点</div>
    				    <select class="form-control" name="shequ">'.$shequselect.'</select>
    			    </div>
    		    </div>
                <p><input type="submit" name="submit" value="开始对接" class="btn btn-primary btn-block"></p>
            </form></div>
            </div>
        </div>';
}else if($act=='data'){
    $rs=$DB->query("SELECT * FROM pre_class WHERE 1 order by sort asc");
    $classselect='<option value="new">--新建各个商品的同名分类--</option><option value="0">未分类</option>';
    while($res = $rs->fetch()){
    	$classselect.='<option value="'.$res['cid'].'">'.$res['name'].'</option>';
    }
    $rs=$DB->query("SELECT * FROM pre_price order by id asc");
    $priceselect='<option value="0">不使用加价模板</option>';
    while($res = $rs->fetch()){
    	$kind = $res['kind']==1?'元':'倍';
    	$priceselect.='<option value="'.$res['id'].'" kind="'.$res['kind'].'" p_2="'.$res['p_2'].'" p_1="'.$res['p_1'].'" p_0="'.$res['p_0'].'" >'.$res['name'].'('.$res['p_2'].$kind.'|'.$res['p_1'].$kind.'|'.$res['p_0'].$kind.')</option>';
    }
    $shequd=$_GET['shequ'];
    $submit=$_GET['submit'];
    $row=$DB->getRow("select * from pre_shequ where id='$shequd' limit 1");
    if($row['type']!='sf')exit('该对接网站类型不支持批量添加商品');
    $rows = third_call('sf', $row, 'class_list');
    $apiclassselect = '<option value="-2">--请选择分类--</option><option value="-1">获取全部商品</option><option value="0">未分类</option>';
    foreach ($rows as $res){
	    $apiclassselect .= '<option value="'.$res['cid'].'">'.$res['name'].'</option>';
	}
    echo'

        <div class="col-sm-5 col-md-4 col-xs-12">
            <a href="./sf_batchgoods.php" class="btn btn-block" style="color:black">
                <i class="fa fa-mail-reply"></i> '.$row['url'].'
            </a><br>
            <div class="block">
                <div class="block-title">
                    <h3 class="panel-title">
                        数据选择
                    </h3>
                    <a href="./sf_synchronization.php" class="pull-right btn btn-default btn-sm" style="margin-top:5px;margin-right:5px">
                        <i class="fa fa-cog"></i> 自动同步设置
                    </a>
                </div>
                <div class="">
			        <div class="form-group">
				        <div class="input-group">
				            <div class="input-group-addon">数据范围</div>
				            <select class="form-control" id="range">
				                <option value="all">不限时间</option>
				                <option value="today">今日上架</option>
				                <option value="yesterday">昨日上架</option>
				            </select>
				            <select class="form-control" id="status">
				                <option value="all">全部商品</option>
				                <option value="no">未对接</option>
				                <option value="yes">已对接</option>
				            </select>
	                    </div>
                    </div>
		            <div class="form-group">
				        <div class="input-group">
				            <div class="input-group-addon">选择分类</div>
				            <select class="form-control" id="cid">'.$apiclassselect.'</select>
	                    </div>
                    </div>
                    <div class="form-group">
				        <div class="input-group">
				            <div class="input-group-addon">搜索内容</div>
				            <input class="form-control" id="kw" value="">
				            <span class="input-group-btn"><a id="search" class="btn btn-default"><i class="fa fa-search"></i> 查询</a></span>
	                    </div>
                    </div>
                </div>
            </div> 
        </div>
        <div class="col-sm-7 col-md-8 col-xs-12">
            <div class="block">
                <div class="block-title">
                    <h3 class="panel-title">批量对接商品</h3>
                </div>
                <div class="">
                    <form action="?" role="form">
    	                <input type="hidden" name="shequ" value="'.$_GET['shequ'].'">
    	                <input type="hidden" name="page" value="1">
    	                <div class="form-group">
    	                    <a id="add_submit" class="btn btn-primary"><i class="fa fa-plus"></i> 批量对接</a>
    	                    <a id="all_submit" class="btn btn-danger"><i class="fa fa-copy"></i> 全部对接</a>
    	                </div>
    	                <div id="content"></div>
    	                <div id="shoplist"><div class="alert alert-warning">请选择对接分类</div></div>
                    </form>
                </div>
            </div>
        </div>';
}
echo '<script src="'.$cdnpublic.'layer/3.1.1/layer.js"></script>
<script type="text/html" id="allhtml">
    <div class="panel-body">
        <div class="form-group">
            <div class="progress progress-striped">
              <div id="progress_bar" class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="40" aria-valuemin="0" aria-valuemax="100" style="width: 0%">
            	<span id="progress_text" class="sr-only">0%</span>
              </div>
            </div>
        </div>
        <div class="form-group">
            <div class="alert alert-info" id="progress_msg">正在准备对接中...</div>
        </div>
    </div>
</script>
<script type="text/html" id="addhtml">
    <div class="form-group">
        <div class="input-group">
            <div class="input-group-addon">保存分类</div>
            <select class="form-control" id="mcid">'.$classselect.'</select>
        </div>
    </div>
    <div class="form-group">
        <div class="input-group">
            <div class="input-group-addon">加价模板</div>
            <select class="form-control" id="prid">'.$priceselect.'</select>
            <span class="input-group-btn"><a href="./price.php" class="btn btn-default">模板管理</a></span>
        </div>
    </div>
</script>
<script src="assets/js/sf_batchgoods.js?ver='.VERSION .'542241111"></script>
</body>
</html>';